Fortran Formats

©1995,1996, Richard B. Winston

Please Register Please Register

Last modified on Wednesday, January 31, 1996 - 5:45:19 PM

All you need to know about the FORTRAN formats in MODFLOW

This is not meant to be a complete description of FORTRAN formats. I only discuss those formats that are used in the input and output files of MODFLOW. For more details, see a textbook on FORTRAN such as Didday and Page (1977).

In many of the example, I include a line such as the following.

123456789012345678901234567890123456789012345

This line is not part of the example input or output. It is there merely to show your position on a line.

Fortran Formats


F format

Here's an example of a "Fixed decimal" FORTRAN format; "15F7.2". The 7 means that 7 spaces on the line are allocated for the particular variable that is being entered. the ".2" is used to specify where the decimal point goes. In this case, if you don't include a decimal point in the number, the decimal point will be just before the last two digits that you entered. The "15" means that up to 15 values in F7.2 format will be on a single line. Blank spaces are treated as 0's by some programs so you'll be sure that the numbers are read properly.

Example:

In the following example, the first line is used to help you keep track of your position in the line. It is not part of the actual input. Blank spaces are represented by
b.

If the format is 20F5.1, the second line of this pair:

12345678901234567890123456789012345
bb354bb27b27.1b.365367.20-89142.1E6

would be interpreted by the program as 35.4, 27.0, 27.1, 0.3653, 67.2, -891.4, 2100000

The first number the program reads is

bb354
Because this is F5.1 format, the program assumes that a decimal point goes before the last digit making the number 35.4.

The second number the program reads is

bb27b
The program treats the final
b
as a 0 and places a decimal point before that final 0. The number is thus 27.0.

The third number the program reads is

27.1b
Once again program treats the final
b
as a 0. In this case, however, the decimal point was already specified so the final number that the program uses is 27.1 not 271.0.

The fourth number the program reads is

.3653
which is interpreted as 0.3653. Note that ordinarily there would only be one digit after the decimal point with F5.1 format but because the decimal point was specified in the input file, we have 4 digits after the decimal for this number. However, if this number were printed in F5.1 format, it would be rounded to 0.4.

The fifth number the program reads is

67.20
which is interpreted as 67.2. Note that there was no blank space between the fourth and fifth numbers in the input file.

The sixth number the program reads is

-8914
which is interpreted as -891.4. Note that you have to include the minus sign for negative numbers.

The seventh number the program reads is

2.1E6
which means "2.1 times 10 raised to the 6'th power" or in other words 2,100,000.

Go back to Fortran Formats
Go back to Contents


E format

E format is similar to F format in many respects. For example, in 11E7.2, the "7" means that the field which will be read is 7 spaces wide and the ".2" means that the decimal point will be shifted to the left by two spaces unless it is explicitly included in the data. Blank spaces are treated as 0's. The "11" means that the program will attempt to read up to 11 items in E7.2 format from each line.

The "E" can be omitted. Thus a number could be entered as 5.43-3 and would be interpreted as .00543. If 543-3 was read in E5.2 format , it would be interpreted as .00543 because the decimal place would be inserted two spaces to the left of the beginning of the exponent ("-3"). Thus E format differs from F format in that a decimal point is inserted in numbers which are in scientific notation and in that the E in scientific notation may be omitted.

Example

In the following example, the first line is used to help you keep track of your position in the line. It is not part of the actual input. Blank spaces are represented by
b.

If the format is 20E5.1, the second line of this pair:

123456789012345678901234567890123456789012345
bb354bb27b27.1b.365367.20-89142.1E6234-3.54-2

would be interpreted as 35.4, 27.0, 27.10, .3653, 67.20, -89.14, 2100000, 0.0234, 0.0054

The first seven numbers are interpreted in the same way as the F format. The eighth number the program reads is

234-3
which is interpreted as 0.0234. First, the decimal place is inserted one place to the left of the
234
to make it
23.4
. An E is assumed to occur between the
234
and the
-3
to make the number
23.4E-3
which means 0.0234

The ninth number the program reads is

.54-2
which is interpreted as 0.0054. The decimal point in the
.54
takes precedence over insertion of a decimal point. An E is assumed to occur between the
.54
and the
-2
so the number is interpreted as
.54E-2
or 0.0054.

Go back to Fortran Formats
Go back to Contents


G format

The G format allows you to print numbers to a certain number of significant digits. Numbers will be printed in an F format if the field width is large enough and an E format otherwise. Numbers will be rounded in printing if they have more significant digits than should be printed. In "7G11.4", the "11" means that the field width is 11 spaces. The ".4" means that 4 significant digits will be printed (Note the difference in meaning from the F format). The "7" means that the program will attempt to read up to 7 fields from each line.

Example

Suppose that the following numbers in computer memory are to be printed in 2G10.3 format.

6.73656
879463.5
0.00000034536
23.1
567.3
.0000045

The numbers would be printed as

123456789012345678901234567890123456789012345
bb6.74bbbbbb8.79E+05
bb3.45E-07bb23.1
bb567.bbbbb4.500E-06

Note that the entire last number could have been printed in a field width of 10 but because the last 4 spaces were reserved for the exponents, it was too long and had to be printed in E format.

Go back to Fortran Formats
Go back to Contents


I format

The integer format differs from real number formats such as the F and E formats in that there is no fractional part and no decimal point. If you attempt to use a decimal point in an integer, the program may end and give you an error message. The format 40I2 means that the width of the field which will be read is 2 spaces and that up to 40 such fields will be read from each line. Blank spaces are interpreted as 0's

Example

If the format is 40I2, the following line
b1b2bb22b33b-2

would be interpreted as 1, 2, 0, 22, 3, 30, -2.

In this example blank spaces are represented by

b
Go back to Fortran Formats
Go back to Contents

A format

The A format is used to enter text (alphanumeric characters). If the format is "20A4", the program will read in 20 blocks of text each 4 characters long for a total of 80 characters. Blanks are treated as blanks and not as 0's.

Example

If the format is "20A4", the following line

123456789012345678901234567890123456789012345
THIS IS A TEST

would be stored in computer memory as

THIS
bISb
AbTE
STbb

If these were printed in 20A4 format, the result would be

THIS IS A TEST

Go back to Fortran Formats
Go back to Contents



©1995,1996, Richard B. Winston,
rwinsto@lsuvm.sncc.lsu.edu
Dept. of Geology and Geophysics
Louisiana State University
Baton Rouge, La 70803
U.S.A.
504-388-2337
Fax 504-388-2302
http://scribe.geol.lsu.edu/rbwinston.html
ftp://aapg.geol.lsu.edu/pub/winston